{include file="pageheader.htm"}
<script type="text/javascript" charset="utf-8" src="../includes/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../includes/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="../includes/ueditor/lang/zh-cn/zh-cn.js"></script>

<div class="tab-div">
  <!-- tab bar -->
  <div id="tabbar-div">
    <p>
    	<span class="tab-front" id="general-tab">基本信息</span>
    	<span class="tab-back" id="content-tab">描述</span>
    	<span class="tab-back" id="goods-tab">推荐商品</span>
	</p>
  </div>
  <!-- tab body -->
  <div id="tabbody-div">
	  <form action="ceping.php" method="post" name="theForm" onsubmit="return validate();">
	    <table cellspacing="1"  id="general-table" cellpadding="3" width="100%">
	      <tr>
	        <td class="label">得分范围:</td>
	        <td><input type="text" name="point_min" size="10" value="{$result.point_min}"/>-<input type="text" name="point_max" size="10" value="{$result.point_max}"/>
	        {$lang.require_field}</td>
	      </tr>
	      <tr>
	        <td class="label">结果:</td>
	        <td><input type="text" name="result" size="40" value="{$result.result}"/>
	        </td>
	      </tr>
	      <!-- <tr>
	        <td class="label">描述:</td>
	        <td><textarea type="text" name="content" cols="40" rows="20">{$result.content}</textarea>
	        {$lang.require_field}</td>
	      </tr> -->
	      
	    </table>
	    <table id="content-table" width="90%" style="display:none">
	      <tr>
            <td>
               
			    <textarea id="content" name="content" style="width:100%;height:300px;">{$result.content}</textarea>
			    <script type="text/javascript">
			    delete(Object.prototype.toJSONString);
			    UE.getEditor('content')
			
			    </script>
			</td>
          </tr>
	    </table>
	    <table width="90%" border="0"  align="center" cellpadding="0" cellspacing="0" id="goods-table" style="display:none;" >
	        <tr>
	          <td colspan="3"><img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
	            <select name="cat_id2">
	              <option value="0">{$lang.all_category}</option>
	              {$cat_list}
	            </select>
	            <select name="brand_id2">
	              <option value="0">{$lang.all_brand}</option>
	              {html_options options=$brand_list}
	            </select>
	            <input type="text" name="keyword2"/>
	            <input name="button" type="button" class="button" onclick="searchGoods('cat_id2', 'brand_id2', 'keyword2')" value="{$lang.button_search}" />          </td>
	        </tr>
	        <!-- 商品列表 -->
	        <tr height="37">
	          <th>所有商品</th>
	          <th>{$lang.handler}</th>
	          <th>已选商品</th>
	        </tr>
	        <tr>
	          <td width="42%">
	          	<select name="source_select" id="source_select" size="20" style="width:100%;height:300px;"  ondblclick="addItem(this)">
	            </select>
	          </td>
	          <td align="center">
	          	<p>
	              <input name="button" type="button" class="button" onclick="addAllItem(document.getElementById('source_select'))" value="&gt;&gt;" />
	            </p>
	            <p>
	              <input name="button" type="button" class="button" onclick="addItem(document.getElementById('source_select'))" value="&gt;" />
	            </p>
	            <p>
	              <input name="button" type="button" class="button" onclick="removeItem(document.getElementById('target_select'))" value="&lt;" />
	            </p>
	            <p>
	              <input name="button" type="button" class="button" value="&lt;&lt;" onclick="removeItem(document.getElementById('target_select'), true)" />
	            </p></td>
	          <td width="42%">
	          	<select name="target_select" id="target_select" size="20" style="width:100%;height:300px" multiple="multiple">
	          	
	            </select>
	          </td>
	        </tr>
	    </table>
	    <div class="button-div">
	    	<input  name="goods" type="hidden" id="goods" value='' />
	        <input type="hidden" name="id" value="{$result.result_id}" />
	        <input type="hidden" name="exam_id" value="{$exam_id}" />
	        <input type="submit" value="{$lang.button_submit}" class="button" />
	        <input type="hidden" name="act" value="{$act}" />
	    </div>
	  </form>
	</div>
  </div>
{insert_scripts files="../js/utils.js,validator.js,selectzone.js,colorselector_topic.js,tab.js"}
<script type="text/javascript">

var myTopic = {$result.goods};
{literal}

onload = function() {
	  startCheckOrder();
	  showTargetList();
	}

function validate()
{
  var validator = new Validator('theForm');
  
  validator.required('point_min', '最低得分不能为空');
  validator.required('point_max', '最高得分不能为空');
  document.getElementById("goods").value = myTopic.toJSONString();
  return validator.passed();
}
function searchGoods(catId, brandId, keyword)
{
  var elements = document.forms['theForm'].elements;
  /* var filters = new Array(); */
  var filters = new Object;
  filters.cat_id = elements[catId].value;
  filters.brand_id = elements[brandId].value;
  filters.keyword = Utils.trim(elements[keyword].value);
  Ajax.call("ceping.php?act=get_goods_list",'JSON='+JSON.stringify(filters) , function(result)
  {
    clearOptions("source_select");
    var obj = document.getElementById("source_select");
    for (var i=0; i < result.content.length; i++)
    {
      var opt   = document.createElement("OPTION");
      opt.value = result.content[i].value;
      opt.text  = result.content[i].text;
      opt.id    = result.content[i].data;
      obj.options.add(opt);
    }
  }, "GET", "JSON");
}

function clearOptions(id)
{
  var obj = document.getElementById(id);
  while(obj.options.length>0)
  {
    obj.remove(0);
  }
}

function addAllItem(sender)
{
  if(sender.options.length == 0) return false;
  for (var i = 0; i < sender.options.length; i++)
  {
    var opt = sender.options[i];
    addItem(null, opt.value, opt.text, opt.id);
  }
}

function addItem(sender, value, text, id)
{
  var target_select = document.getElementById("target_select");
  
  var newOpt   = document.createElement("OPTION");
  if (sender != null)
  {
    if(sender.options.length == 0) return false;
    var option = sender.options[sender.selectedIndex];
    
    newOpt.value = option.value;
    newOpt.text  = option.text;
  }
  else
  {
    newOpt.value = value;
    newOpt.text  = text;
    newOpt.id  = id;
  }
  if (targetItemExist(newOpt)) return false;
  /* if (target_select.length>=50)
  {
    alert(item_upper_limit);
  } */
  target_select.options.add(newOpt);
  
  if(!myTopic)
  {
    myTopic = new Array();
  }
  myTopic.push(newOpt.text + "|" + newOpt.value);
  
}

// 商品是否存在
function targetItemExist(opt)
{
  var options = document.getElementById("target_select").options;
  for ( var i = 0; i < options.length; i++)
  {
    if(options[i].value == opt.value) 
    {
      return true;
    }
  }
  return false;
}



function showTargetList()
{
  clearOptions("target_select");
  for ( var i = 0; i < myTopic.length; i++)
  {
    var newOpt    = document.createElement("OPTION");
    var arr = myTopic[i].split('|');
    newOpt.value  = arr[1];
    newOpt.text   = arr[0];
    document.getElementById("target_select").options.add(newOpt);
  }
}

function removeItem(sender,isAll)
{
  
  var key = 'default';
  
  var arr = myTopic;
  if (!isAll)
  {
	if(typeof(sender.options[sender.selectedIndex])=='undefined'){
		alert('请选择项目');
	}
	else{
		var goodsName = sender.options[sender.selectedIndex].text;
	    for (var j = 0; j < arr.length; j++)
	    {
	      if (arr[j].indexOf(goodsName) >= 0)
	      {
	          myTopic.splice(j,1);
	      }
	    }

	    for (var i = 0; i < sender.options.length;)
	    {
	      if (sender.options[i].selected) {
	        sender.remove(i);
	        myTopic.splice(i, 0);
	      }
	      else
	      {
	        i++;
	      }
	    }
	}
    
  }
  else
  {
    myTopic = new Array();
    sender.innerHTML = "";
  }
}

{/literal}  

</script>
{include file="pagefooter.htm"}